﻿@using Orchard.Core.Contents
@using OShop.Models

@{
    Script.Require("OShop");
    
    CustomerPart contentPart = Model.ContentPart;
}

@if (Authorizer.Authorize(Permissions.EditContent, contentPart)) {
    @Html.ActionLink(T("Create new address").Text, "CreateAddress", new { area = "OShop" })
}
@if (contentPart.Addresses.Any()) {
    <h2>@T("Your addresses")</h2>
    using (Html.BeginFormAntiForgeryPost(Url.Action("Index", "Customer", new { area = "OShop" }))) {
        <fieldset>
            <select id="CustomerAddress" name="CustomerAddressId">
                @foreach (var address in contentPart.Addresses) {
                    <option value="@address.ContentItem.Id" @(address.IsDefault ? "selected" : "")>@address.AddressAlias</option>
                }
            </select>
        @if (Authorizer.Authorize(Permissions.EditContent, contentPart)) {
            <button type="submit" name="Action" value="Edit">@T("Edit")</button>
            <button type="submit" name="Action" value="Remove" class="oshop-confirm" data-msg="@T("Are you sure you want to remove this address ?")">@T("Remove")</button>
        }
            <div id="CustomerAddressPreview" class="address-preview">
            </div>
        </fieldset>
    }
}

@using (Script.Foot()) {
    <script type="text/javascript">
//<![CDATA[
    $(function () {
        $("#CustomerAddress").OShopAddressPreview("@Url.Action("PreviewAddress", "Customer", new { area = "OShop" })/", "#CustomerAddressPreview");
    })
//]]>
    </script>
}